package com.walixiwa.sample;

import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.dueeeke.videoplayer.player.VideoView;
import com.walixiwa.player.VideoViewControl;

public class MainActivity extends AppCompatActivity {

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //VideoViewManager.setConfig(VideoViewConfig.newBuilder().setPlayerFactory(IjkPlayerFactory.create()).build());

        videoView = findViewById(R.id.videoView);

        VideoViewControl setter = new VideoViewControl().with(videoView);
        setter.enableOrientation();
        setter.enableErrorView();
        setter.enableCompleteView();
        setter.enableEpisodeView();
        setter.enableScaleView();
        setter.enableSpeedView();
        setter.enableVodControlView();
        /*setter.enableProgressManager();*/
        setter.setTitles(DataConfig.titles);
        setter.setUrls(DataConfig.urls);
        setter.autoPlay(0);

    }


    @Override
    protected void onPause() {
        super.onPause();
        videoView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        videoView.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        videoView.release();
    }

    private long lastTime = 0;

    @Override
    public void onBackPressed() {
        if (videoView.isFullScreen()) {
            videoView.onBackPressed();
            return;
        }
        if (videoView.isPlaying()) {
            if ((System.currentTimeMillis() - lastTime) > 2000) {
                Toast.makeText(this, "再按一次退出播放", Toast.LENGTH_SHORT).show();
                lastTime = System.currentTimeMillis();
                return;
            }
        }
        videoView.release();
        super.onBackPressed();
    }
}
